import DocumentPicker from 'react-native-document-picker';
import RNFS from 'react-native-fs';

export const pickFile = async () => {
  try {
    const result = await DocumentPicker.pick({
      type: [DocumentPicker.types.plainText],
    });
    return result[0];
  } catch (err) {
    if (DocumentPicker.isCancel(err)) {
      console.log('User cancelled file picker');
    } else {
      console.error('Error picking file:', err);
    }
    return null;
  }
};

export const readFile = async (path: string) => {
  try {
    const content = await RNFS.readFile(path, 'utf8');
    return content;
  } catch (err) {
    console.error('Error reading file:', err);
    return null;
  }
};
